﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DBAccessor.Accessor;
using DBList.Entities;
using AlanUtilities;

public partial class MenDianReg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		operaterLabel.Text = @"";
		String strUID = OperateControl.PickupAvaiableUserID(this);
		if (strUID != null)	operaterLabel.Text = strUID;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strUser = operaterLabel.Text;
        int nUserID = 0;
        if (int.TryParse(strUser, out nUserID))
        {
            string strTiaoMa = txtTiaoMaEdit.Text.Trim();
            if(strTiaoMa != null && strTiaoMa.Length > 1)
            {
				MsgAccessor msgAcce = new MsgAccessor();
				int nRet = msgAcce.PickupGoods(1, nUserID, strTiaoMa, null, null, null);
                tiaoma.Text = strTiaoMa;
                txtTiaoMaEdit.Text = @"";
                ariseTime.Text = @"";
                mdAddress.Text = @"";
                flowInfo.Text = @"";
				flowInfo.Text = @"失败！";
                if (nRet == -100) {
					ariseTime.Text = @"该条码不存在！";
                }
                else if (nRet == -101)
                {
					ariseTime.Text = @"该礼券还未激活！";
                }
                else if(nRet == -102)
                {
                    TiaoMaRecord tmRec = msgAcce.GetOneTiaoMaRecord(strTiaoMa, null);
                    if(tmRec.FlowID == 2){
						ariseTime.Text = @"该礼券已经下过订单！";
                    }
                    else if(tmRec.FlowID == 3){
						ariseTime.Text = @"该礼券已经发货出去！";
                    }
                    else if(tmRec.FlowID == 1){
                        ariseTime.Text = tmRec.ApplyTime.ToString();
						ariseTime.Text += @"提过货！";

                        MemberAccessor  memAcce = new MemberAccessor();
						UserData memData = memAcce.GetMemberInfo(tmRec.Applier);
                        mdAddress.Text = memData.Address;
                    }
					else if (tmRec.FlowID >= 444)
					{
						ariseTime.Text = @"该礼券已经作废！";
					}
                }
				else if (nRet == 0){
					flowInfo.Text = @"成功！";
				}
				else {
					flowInfo.Text = @"失败！";
					ariseTime.Text = @"访问出现异常，请重试！";
				}
            }
        }
    }
}
